package com.example.emailWeb.Socket.SimpleDemo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ClientServer extends Thread{
    /**
     * 监听是否有人发起连接
     */
    private ServerSocket server = null;
    Socket socket = null;
    public ClientServer(int port) throws IOException {
        server = new ServerSocket(port);
    }

    @Override
    public void run() {
        while (true) {
            try {
                socket = server.accept();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("收到一个连接");
            ReceiveDataBuffer receiveDataBuffer = new ReceiveDataBuffer(socket);
            DataBuffer dataBuffer = receiveDataBuffer.getDataBuffer();
            System.out.println("收到dataBuffer");
            System.out.println(dataBuffer);
            //处理该dataBuffer
            try {
                HandleDataBuffer handleDataBuffer = new HandleDataBuffer(dataBuffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
